//
//  ViewController.m
//  TabBarView
//
//  Created by HaiSheng on 15/8/8.
//  Copyright (c) 2015年 huanghaisheng. All rights reserved.
//

#import "ViewController.h"
#import "UIColor+External.h"
#import "TabBarView.h"


@interface ViewController ()<TabBarViewDelegate>

@property (nonatomic, strong) TabBarView *tabBar;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self addTabbar];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 初始化Tabbar
- (void)addTabbar
{
    UIColor *highlightColor = [UIColor colorWithHexString:@"#ff5b7e"];
    UIColor *normalColor = [UIColor colorWithHexString:@"#888888"];
    NSArray *items = @[@{kTitle:@"瘦身",
                         kImgNormal:@"tab_icon_slim",
                         kImgHighlighted:@"tab_icon_slim_h",
                         kHighlightedColor:highlightColor,
                         kNormalColor:normalColor},
                       @{kTitle:@"社区",
                         kImgNormal:@"tab_icon_community",
                         kImgHighlighted:@"tab_icon_community_h",
                         kHighlightedColor:highlightColor,
                         kNormalColor:normalColor},
                       @{kTitle:@"发现",
                         kImgNormal:@"tab_icon_discover",
                         kImgHighlighted:@"tab_icon_discover_h",
                         kHighlightedColor:highlightColor,
                         kNormalColor:normalColor},
                       @{kTitle:@"我的",
                         kImgNormal:@"tab_icon_mine",
                         kImgHighlighted:@"tab_icon_mine_h",
                         kHighlightedColor:highlightColor,
                         kNormalColor:normalColor}];
    
    CGRect frame = CGRectMake(0,self.view.frame.size.height - 49, [UIScreen mainScreen].bounds.size.width, 49);
    self.tabBar = [[TabBarView alloc] initWithFrame:frame Items:items BarStyle:TabItemStyleTitleAndIcon SelectedIndex:0];
    self.tabBar.delegate = self;
    
    [self.view addSubview:self.tabBar];
    
}

#pragma mark - TabBarViewDelegate
- (BOOL)tabBarView:(TabBarView *)view shouldSelectAtIndex:(NSInteger)index
{
    NSLog(@"%zd", index);
    return YES;
}

- (void)tabBarView:(TabBarView *)view didSelectAtIndex:(NSInteger)index
{
    NSLog(@"%zd", index);
}


@end
